package com.ymatou.iapi.trading.ordersync.service;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;

import org.json.JSONObject;

import com.ymatou.iapi.trading.operate.parameter.enums.LogisticsTypeEnum;
import com.ymatou.iapi.trading.operate.parameter.req.ChangeLogisticsTypeReq;
import com.ymatou.iapi.trading.operate.parameter.req.ChangeOrderDiscountBean;
import com.ymatou.iapi.trading.operate.parameter.req.DispatchedBean;
import com.ymatou.iapi.trading.operate.service.ChangeLogisticsTypeCall;
import com.ymatou.iapi.trading.operate.service.ChangeOrderDiscountCall;
import com.ymatou.iapi.trading.operate.service.DispatchedCall;
import com.ymatou.iapi.trading.ordersync.parameter.OrderBean;
import com.ymatou.iapi.trading.ordersync.parameter.OrderEsBean;
import com.ymatou.iapi.trading.ordersync.parameter.OrderSyncCmdEnum;
import com.ymatou.iapi.trading.ordersync.parameter.Product;
import com.ymatou.iapi.trading.ordersync.parameter.SellerIndexBean;
import com.ymatou.iapi.trading.ordersync.parameter.SyncOrderCmdBean;
import com.ymatou.iapi.trading.ordersync.parameter.UserIndexBean;
import com.ymatou.iapi.trading.ordersync.parameter.po.SubProduct;
import com.ymatou.tool.FormatUtil;
import com.ymt.base.YmatouEasyCall;
import com.ymt.core.tool.Logger;
import com.ymttest.common.enums.BillTypeEnum;
import com.ymttest.database.mongo.SyncCommandWapper;
import com.ymttest.database.sqlwapper.CommandQueryWapper;
import com.ymttest.database.sqlwapper.DefaultWapper;
import com.ymttest.utils.DataUtil;
import com.ymttest.utils.TestDataManager;
import com.ymttest.utils.YMTDateUtil;

public class SyncVerifyService {

	/**
	 * 根据订单查询同步到mongo 数据结果
	 * 
	 * @param orderId
	 * */
	public static boolean getSyncResult(Integer orderId) {

		Long time1 = System.currentTimeMillis();
		String sqlCmd = "select id from Ymt_SyncOrderCmd where orderid="
				+ orderId + " order by addtime desc";
		String cmdId = (String) new DefaultWapper().executeSql(sqlCmd).get(0)
				.get("id");
		try {
			SyncCommandWapper syncCommandWapper = new SyncCommandWapper();
			Map result = new HashMap();
			int count = 0;
			while (count < 60) {
				Thread.sleep(500);
				result = syncCommandWapper.getSyncCommand(cmdId);
				if (result == null) {

					count++;
					continue;
				}

				if ((Integer) result.get("ost") >= 1
						&& (Integer) result.get("sst") >= 1
						&& (Integer) result.get("ust") >= 1
						&& ((Integer) result.get("est") >= 1 || (Integer) result
								.get("est") == -2)) {
					Long time2 = System.currentTimeMillis();
					Logger.debug("同步到mongo及ES用时:" + (time2 - time1) / 1000
							+ "s");
					return true;
				}

				count++;
			}
			Long time3 = System.currentTimeMillis();
			if (result == null) {
				Logger.debug("同步到mongo及ES用时:" + (time3 - time1) / 1000
						+ "s, mongo 结果为null，同步失败");
				return false;
			}

		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		Long time4 = System.currentTimeMillis();
		Logger.debug("同步到mongo及ES用时:" + (time4 - time1) / 1000 + "s, 同步失败");
		return false;
	}

	/**
	 * 调用接口查询同步到es order 数据
	 * 
	 * @param orderId
	 * */
	public static OrderEsBean getOrderFromES(Integer orderId) {

		YmatouEasyCall OrderFromMongoCall = new YmatouEasyCall("", "POST",
				"JSON");
		OrderEsBean order = new OrderEsBean();
		String orderJson = "{\"id\":" + orderId + "}";
		OrderFromMongoCall
				.setUrl("http://es.trading.iapi.ymatou.com/api/OrderSync/GetOrder");
		OrderFromMongoCall.setData(orderJson);
		try {
			OrderFromMongoCall.callService();
			JSONObject jsonObject = new JSONObject(
					OrderFromMongoCall.getReturnData()).getJSONObject("data");

			order = (OrderEsBean) FormatUtil.GSONToObject(
					jsonObject.getString("order"), OrderEsBean.class);
			Logger.debug("returndata:" + OrderFromMongoCall.getReturnData());
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return order;
	}

	/**
	 * 调用接口查询mongo 数据 order 数据
	 * 
	 * @param orderId
	 * */
	public static OrderBean getOrderFromMongo(Integer orderId) {

		YmatouEasyCall OrderFromMongoCall = new YmatouEasyCall("", "POST",
				"JSON");
		OrderBean order = new OrderBean();
		String orderJson = "{\"orderId\":" + orderId + "}";
		OrderFromMongoCall
				.setUrl("http://ordersync.trading.iapi.ymatou.com/api/getOrder");
		OrderFromMongoCall.setData(orderJson);
		try {
			OrderFromMongoCall.callService();
			String jsonOrder = new JSONObject(
					OrderFromMongoCall.getReturnData()).getString("order");
			order = (OrderBean) FormatUtil.GSONToObject(jsonOrder,
					OrderBean.class);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return order;
	}

	/**
	 * 调用接口查询mongo 数据 SellerIndex 数据
	 * 
	 * @param orderId
	 * */
	public static SellerIndexBean getSellerIndexBeanFromMongo(Integer orderId,
			int sellerId) {

		YmatouEasyCall OrderFromMongoCall = new YmatouEasyCall("", "POST",
				"JSON");
		SellerIndexBean sellerIndexBean = new SellerIndexBean();
		String orderJson = "{\"orderId\":" + orderId + ",\"sellerId\":"
				+ sellerId + "}";
		OrderFromMongoCall
				.setUrl("http://ordersync.trading.iapi.ymatou.com/api/getSellerIndex");
		OrderFromMongoCall.setData(orderJson);
		try {
			OrderFromMongoCall.callService();
			String sellerIndex = new JSONObject(
					OrderFromMongoCall.getReturnData())
					.getString("sellerIndex");

			sellerIndexBean = (SellerIndexBean) FormatUtil.GSONToObject(
					sellerIndex, SellerIndexBean.class);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return sellerIndexBean;
	}
	/**
	 * 调用接口查询mongo 数据 SellerIndex 数据
	 * 
	 * @param orderId
	 * @param userId
	 * */
	public static UserIndexBean getUserIndexBeanFromMongo(Integer orderId,
			int userId) {

		YmatouEasyCall OrderFromMongoCall = new YmatouEasyCall("", "POST",
				"JSON");
		UserIndexBean userIndexBean = new UserIndexBean();
		String orderJson = "{\"orderId\":" + orderId + ",\"userId\":" + userId
				+ "}";
		OrderFromMongoCall
				.setUrl("http://ordersync.trading.iapi.ymatou.com/api/getUserIndex");
		OrderFromMongoCall.setData(orderJson);
		try {
			OrderFromMongoCall.callService();

			String userIndex = new JSONObject(
					OrderFromMongoCall.getReturnData()).getString("userIndex");

			userIndexBean = (UserIndexBean) FormatUtil.GSONToObject(userIndex,
					UserIndexBean.class);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return userIndexBean;
	}
	/**
	 * 码头保存发货物流单号
	 * 
	 * @param orderId
	 * @param sellerId
	 * */
	public static String saveDeliverSummary(Integer orderId, int sellerId) {

		/*		String billCode_sit1 = "DB683214922US";
				String billCode_uat = "DB753209166US";*/

		String billCode = "Auto" + TestDataManager.getRandomNum(5);

		try {
			YmatouEasyCall SaveDeliverSummaryCall = new YmatouEasyCall("",
					"POST", "JSON");
			StringBuffer saveDeliverSummaryString = new StringBuffer();
			saveDeliverSummaryString
					.append("{\"SaveDeliverSummaryInfos\":[{\"BillCode\":\"");
			saveDeliverSummaryString.append(billCode);
			saveDeliverSummaryString.append("\",");
			saveDeliverSummaryString
					.append("\"CanReDelivery\":0,\"DeliverType\":2,\"ExpressCode\":\"xlobo\",\"InnerExpressCode\":\"\",\"IsChinaDeliver\":false,");
			saveDeliverSummaryString.append("\"OrderId\":");
			saveDeliverSummaryString.append(orderId);
			saveDeliverSummaryString.append(",");
			saveDeliverSummaryString
					.append("\"Provider\":\"洋码头官方合作物流（xLobo贝海国际速递）\",");
			saveDeliverSummaryString.append("\"SellerId\":");
			saveDeliverSummaryString.append(sellerId);
			saveDeliverSummaryString.append(",");
			saveDeliverSummaryString.append("\"Weight\":10}]}");
			SaveDeliverSummaryCall
					.setUrl("http://orderdelivery.iapi.ymatou.com/api/Deliver/SaveDeliverSummary");

			SaveDeliverSummaryCall.setData(saveDeliverSummaryString.toString());
			Logger.comment("发货处理");
			SaveDeliverSummaryCall.callService();

			if (new JSONObject(SaveDeliverSummaryCall.getReturnData())
					.getInt("Code") == 200)
				return billCode;

		} catch (Exception e) {
			// TODO: handle exception
		}

		return null;

	}

	/**
	 * 修改运单号
	 * 
	 * @param orderId
	 * @param sellerId
	 * */
	public static void modifyDeliverBillCode(Integer orderId, int sellerId,
			String newBillCode, String oldBillCode) {
		try {
			YmatouEasyCall SaveDeliverSummaryCall = new YmatouEasyCall("",
					"POST", "JSON");
			StringBuffer saveDeliverSummaryString = new StringBuffer();

			saveDeliverSummaryString.append("{\"NewBillCode\":\"");
			saveDeliverSummaryString.append(newBillCode);
			saveDeliverSummaryString.append("\",");
			saveDeliverSummaryString.append("\"OldBillCode\":\"");
			saveDeliverSummaryString.append(oldBillCode);
			saveDeliverSummaryString.append("\",");
			saveDeliverSummaryString.append("\"SellerId\":");
			saveDeliverSummaryString.append(sellerId);
			saveDeliverSummaryString.append(",");
			saveDeliverSummaryString.append("\"OrderId\":");
			saveDeliverSummaryString.append(orderId);
			saveDeliverSummaryString.append("}");

			SaveDeliverSummaryCall
					.setUrl("http://orderdelivery.iapi.ymatou.com/api/Deliver/ModifyDeliverBillCode");

			SaveDeliverSummaryCall.setData(saveDeliverSummaryString.toString());
			Logger.comment("发货处理");
			SaveDeliverSummaryCall.callService();

			if (new JSONObject(SaveDeliverSummaryCall.getReturnData())
					.getInt("Code") == 200)
				;

		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}

	}
	/**
	 * 非贝海发货
	 * 
	 * @param orderId
	 * @param sellerId
	 */
	public static String dispatched(Integer orderId, int sellerId) {
		String DeliverSummary = saveDeliverSummary(orderId, sellerId);

		try {

			DispatchedBean dispatchedbean = new DispatchedBean();
			DispatchedCall dispatchedcall = new DispatchedCall();

			dispatchedbean.setBillType(BillTypeEnum.YMTAPI.getValue());
			// 物流单号
			dispatchedbean.setDeliverSummary(DeliverSummary);
			dispatchedbean.setDeliverType("0");
			dispatchedbean.setOrderId(orderId);
			dispatchedbean.setProvider("贝海");
			dispatchedbean.setSellerUserId(sellerId);
			dispatchedbean.setSource(1);
			dispatchedbean.setProviderCode("TY160");

			BigDecimal Weight = new BigDecimal(10);
			dispatchedbean.setWeight(Weight);// 重量
			dispatchedbean.setIsShippedByXlobo(true);
			dispatchedcall.setData(false, dispatchedbean);
			Logger.comment("订单:" + orderId + "卖家:" + sellerId + "发货");
			dispatchedcall.callService();
			Logger.debug("发货send：" + dispatchedcall.getEntityString());
			Logger.debug("发货response：" + dispatchedcall.getReturnData());
		} catch (Exception e) {
			e.printStackTrace();
		}
		return DeliverSummary;
	}
	public static void verify(Integer orderId, int userId, int sellerId) {

		syncOrderCmd(orderId, OrderSyncCmdEnum.UPDATE_USER);

		try {
			Thread.sleep(2000);
		} catch (InterruptedException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}

		OrderBean orderMongo = getOrderFromMongo(orderId);
		UserIndexBean userIndexBean = getUserIndexBeanFromMongo(orderId, userId);
		SellerIndexBean sellerIndexBean = getSellerIndexBeanFromMongo(orderId,
				sellerId);

		OrderEsBean orderEsBean = getOrderFromES(orderId);

		Logger.comment("校验订单号orderId:" + orderId);

		try {

			//查询sql 订单相关的全量表数据
			OrderBean orderSql = new CommandQueryWapper()
					.selectAllOrderInfoByOrderId(orderId);

			Logger.comment("校验Mongo库order表数据");

			Logger.comment("比对sql数据库Ymt_Orders表数据");

			DataUtil.verify(orderSql.getId(), orderMongo.getId(), "验证OrderId");

			// DataUtil.verify(orderSql.getTimeMongoAdd(),
			// orderMongo.getTimeMongoAdd(), "验证timeMongoAdd");
			// DataUtil.verify(orderSql.getTimeMongoUpdate(),
			// orderMongo.getTimeMongoUpdate(), "验证timeMongoUpdate");
			DataUtil.verify(orderSql.getMainOrderId(),
					orderMongo.getMainOrderId(), "验证iMainOrderId");
			DataUtil.verify(orderSql.getUserId(), orderMongo.getUserId(),
					"验证iUserId");
			DataUtil.verify(orderSql.getSellerId(), orderMongo.getSellerId(),
					"验证iBuyerid");
			DataUtil.verifyDateEquals(orderSql.getAddTime(),
					orderMongo.getAddTime(), "验证dAddTime");
			DataUtil.verify(orderSql.getTradingId(), orderMongo.getTradingId(),
					"验证iTradingId");
			DataUtil.verify(orderSql.getTradingStatus(),
					orderMongo.getTradingStatus(), "验证iTradingStatus");
			DataUtil.verifyDateEquals(orderSql.getAcceptTime(),
					orderMongo.getAcceptTime(), "验证dAcceptTime");
			DataUtil.verifyDateEquals(orderSql.getDeliveryTime(),
					orderMongo.getDeliveryTime(), "验证dDispathTime");
			DataUtil.verifyDateEquals(orderSql.getPaidTime(),
					orderMongo.getPaidTime(), "验证dPaidTime");
			DataUtil.verifyDateEquals(orderSql.getReceiveTime(),
					orderMongo.getReceiveTime(), "验证dConfirmedTime");
			DataUtil.verify(orderSql.getApplyPostTime(),
					orderMongo.getApplyPostTime(), "验证dApplyPostPayTime");
			DataUtil.verifyDateEquals(orderSql.getPostTime(),
					orderMongo.getPostTime(), "验证dPostPaidTime");
			DataUtil.verifyDateEquals(orderSql.getCancelTime(),
					orderMongo.getCancelTime(), "验证dCancelTime");
			DataUtil.verify(orderSql.getRiskStatus(),
					orderMongo.getRiskStatus(), "验证iRiskVerifiedStatus");
			DataUtil.verify(orderSql.getUserLogin(), orderMongo.getUserLogin(),
					"验证sBuyerLoginId");
			DataUtil.verify(orderSql.getSellerLogin(),
					orderMongo.getSellerLogin(), "验证sSellerLoginId");
			DataUtil.verify(orderSql.getLocalDelivery(),
					orderMongo.getLocalDelivery(), "验证bDomesticDelivered");
			DataUtil.verify(orderSql.getDeleted(), orderMongo.getDeleted(),
					"验证bDeleted");
			DataUtil.verify(orderSql.getEvaluated(), orderMongo.getEvaluated(),
					"验证bEvaluated");
			DataUtil.verify(orderSql.getRemarkLevel(),
					orderMongo.getRemarkLevel(), "验证iRemarkLevel");
			DataUtil.verify(orderSql.getAutoCancelHour(),
					orderMongo.getAutoCancelHour(), "验证fAutoCancelOrderHours");
			DataUtil.verify(orderSql.getXlobo(), orderMongo.getXlobo(),
					"验证bShippedByXlobo");
			DataUtil.verify(orderSql.getYmtCouponAmount(),
					orderMongo.getYmtCouponAmount(), "验证fYmtCouponAmount");
			DataUtil.verify(orderSql.getYmtCouponCode(),
					orderMongo.getYmtCouponCode(), "验证sYmtCouponCode");
			DataUtil.verify(orderSql.getSellerCouponAmount(),
					orderMongo.getSellerCouponAmount(), "验证fSellerCouponAmount");
			DataUtil.verify(orderSql.getSellerPromotionAmount(),
					orderMongo.getSellerPromotionAmount(),
					"验证fSellerPromotionAmount");
			DataUtil.verify(orderSql.getPayableAmount(),
					orderMongo.getPayableAmount(), "验证fPayableAmount");
			DataUtil.verify(orderSql.getFreight(), orderMongo.getFreight(),
					"验证fFreight");
			DataUtil.verify(orderSql.getOrderPrice(),
					orderMongo.getOrderPrice(), "验证fOrderPrice");
			DataUtil.verify(orderSql.getTotalPrice(),
					orderMongo.getTotalPrice(), "验证fTotalPrice");
			DataUtil.verify(orderSql.getPreDiscount(),
					orderMongo.getPreDiscount(), "验证fOrderDiscount");
			DataUtil.verify(orderSql.getPostDiscount(),
					orderMongo.getPostDiscount(), "验证fDiscount");
			DataUtil.verify(orderSql.getAddress(), orderMongo.getAddress(),
					"验证sAddress");
			DataUtil.verify(orderSql.getPostCode(), orderMongo.getPostCode(),
					"验证sPostCode");
			DataUtil.verify(orderSql.getReceiver(), orderMongo.getReceiver(),
					"验证sReceivePerson");
			DataUtil.verify(orderSql.getPhone(), orderMongo.getPhone(),
					"验证sPhone");
			DataUtil.verify(orderSql.getTelephone(), orderMongo.getTelephone(),
					"验证sTelephone");
			DataUtil.verify(orderSql.getEmail(), orderMongo.getEmail(),
					"验证sEmail");
			DataUtil.verify(orderSql.getComment(), orderMongo.getComment(),
					"验证sLeaveWord");
			DataUtil.verify(orderSql.getCanEvaluate(),
					orderMongo.getCanEvaluate(), "验证bCanEvaluate");

			Logger.comment("比对sql数据库Ymt_OrderExt表数据");

			DataUtil.verify(orderSql.getPlatSource(),
					orderMongo.getPlatSource(), "验证sOrderSource");
			DataUtil.verify(orderSql.getNeedUploadIdCard(),
					orderMongo.getNeedUploadIdCard(), "验证bIsNeedUploadIdCard");
			DataUtil.verify(orderSql.getUploadedIdCard(),
					orderMongo.getUploadedIdCard(), "验证bHaveUploadedIdCard");
			DataUtil.verify(orderSql.getNewSeller(), orderMongo.getNewSeller(),
					"验证bNewSellerOrder");
			DataUtil.verify(orderSql.getNewUser(), orderMongo.getNewUser(),
					"验证bNewCustomerOrder");
			DataUtil.verify(orderSql.getFirst(), orderMongo.getFirst(),
					"验证bIsFirstOrder");
			DataUtil.verify(orderSql.getDeliveryChina(),
					orderMongo.getDeliveryChina(), "验证deliveryChina");

			DataUtil.verify(orderSql.getPayChannel(),
					orderMongo.getPayChannel(), "验证sPayChannel");

			DataUtil.verify(orderSql.getPayId(), orderMongo.getPayId(),
					"验证第三方支付交易号payId");

			DataUtil.verify(orderSql.getTradeNo(), orderMongo.getTradeNo(),
					"验证支付方式tradeNo");

			DataUtil.verify(orderSql.getReason(), orderMongo.getReason(),
					"验证sReason");
			DataUtil.verify(orderSql.getContent(), orderMongo.getContent(),
					"验证sellerCont");
			DataUtil.verify(orderSql.getNoteTime(), orderMongo.getNoteTime(),
					"验证dAddTime");
			DataUtil.verify(orderSql.getAutoConfirm(),
					orderMongo.getAutoConfirm(), "验证bAutoConfirmReceive");

			Logger.comment("比对sql数据库Ymt_OrderState表数据");

			DataUtil.verify(orderSql.getFund().getPaidCash(), orderMongo
					.getFund().getPaidCash(), "验证fPaidAmountOfCash");
			DataUtil.verify(orderSql.getFund().getPostCash(), orderMongo
					.getFund().getPostCash(), "验证fPostPaidAmountOfCash");
			DataUtil.verify(orderSql.getFund().getRefundCash(), orderMongo
					.getFund().getRefundCash(), "验证fRefundedAmountOfCash");
			DataUtil.verify(orderSql.getFund().getYmtCoupon(), orderMongo
					.getFund().getYmtCoupon(), "验证fPaidAmountOfYmtCoupon");
			DataUtil.verify(orderSql.getFund().getSellerCoupon(), orderMongo
					.getFund().getSellerCoupon(), "验证fPaidAmountOfSellerCoupon");
			DataUtil.verify(orderSql.getFund().getDiscount3P(), orderMongo
					.getFund().getDiscount3P(), "验证fDiscountOfThirdParty");
			DataUtil.verify(orderSql.getFund().getPaidGif(), orderMongo
					.getFund().getPaidGif(), "验证fPaidAmountOfGift");
			DataUtil.verify(orderSql.getFund().getRefundGif(), orderMongo
					.getFund().getRefundGif(), "验证fRefundedAmountOfGift");
			DataUtil.verify(orderSql.getFund().getPaidFreeCard(), orderMongo
					.getFund().getPaidFreeCard(), "验证fPaidAmountOfFreeCard");
			DataUtil.verify(orderSql.getFund().getRefundCoupon(), orderMongo
					.getFund().getRefundCoupon(), "验证fRefundedAmountOfCoupon");
			DataUtil.verify(orderSql.getFund().getRefundDiscount3P(),
					orderMongo.getFund().getRefundDiscount3P(),
					"验证fRefundedDiscountOfThirdParty");
			DataUtil.verify(orderSql.getFund().getPaidGif(), orderMongo
					.getFund().getPaidGif(), "验证fPaidAmountOfGift");

			Logger.comment("比对sql数据库Ymt_OrderInfo表数据");

			for (int i = 0; i < orderSql.getProducts().size(); i++) {

				Logger.comment("校验第" + (i + 1) + "个商品");

				DataUtil.verify(orderSql.getProducts().get(i).getItemId(),
						orderMongo.getProducts().get(i).getItemId(),
						"验证sOrderInfoId");
				DataUtil.verify(
						orderSql.getProducts().get(i).getDeliveryType(),
						orderMongo.getProducts().get(i).getDeliveryType(),
						"验证iCatalogStatus");
				DataUtil.verify(orderSql.getProducts().get(i).getStockStatus(),
						orderMongo.getProducts().get(i).getStockStatus(),
						"验证iCatalogType");
				DataUtil.verify(orderSql.getProducts().get(i).getPrdPrice(),
						orderMongo.getProducts().get(i).getPrdPrice(),
						"验证fProductPrice");
				DataUtil.verify(orderSql.getProducts().get(i).getPrdDiscount(),
						orderMongo.getProducts().get(i).getPrdDiscount(),
						"验证fDiscount");
				DataUtil.verify(orderSql.getProducts().get(i).getPrdPrePrice(),
						orderMongo.getProducts().get(i).getPrdPrePrice(),
						"验证fOriginalPrice");
				DataUtil.verify(orderSql.getProducts().get(i)
						.getPrdOriginalPrice(), orderMongo.getProducts().get(i)
						.getPrdOriginalPrice(), "验证fProductOriginalPrice");
				DataUtil.verify(
						orderSql.getProducts().get(i).getPropertyInfo(),
						orderMongo.getProducts().get(i).getPropertyInfo(),
						"验证sPropertyInfo");
				DataUtil.verify(orderSql.getProducts().get(i).getPrdCount(),
						orderMongo.getProducts().get(i).getPrdCount(),
						"验证iAmount");
				DataUtil.verify(orderSql.getProducts().get(i).getCataId(),
						orderMongo.getProducts().get(i).getCataId(),
						"验证sCatalogId");
				DataUtil.verify(orderSql.getProducts().get(i).getCata1Id(),
						orderMongo.getProducts().get(i).getCata1Id(),
						"验证iProductMainCategoryId");
				DataUtil.verify(orderSql.getProducts().get(i).getCata2Id(),
						orderMongo.getProducts().get(i).getCata2Id(),
						"验证iProductSubCategoryId");
				DataUtil.verify(orderSql.getProducts().get(i).getCata3Id(),
						orderMongo.getProducts().get(i).getCata3Id(),
						"验证iProductThirdCategoryId");
				DataUtil.verify(orderSql.getProducts().get(i).getBrandId(),
						orderMongo.getProducts().get(i).getBrandId(),
						"验证iProductBrandId");
				DataUtil.verify(orderSql.getProducts().get(i).getSku(),
						orderMongo.getProducts().get(i).getSku(), "验证sSKU");
				DataUtil.verify(orderSql.getProducts().get(i).getProductId(),
						orderMongo.getProducts().get(i).getProductId(),
						"验证sProductId");
				DataUtil.verify(orderSql.getProducts().get(i).getPicUrl(),
						orderMongo.getProducts().get(i).getPicUrl(),
						"验证sPictureUrl");
				DataUtil.verify(orderSql.getProducts().get(i).getTitle(),
						orderMongo.getProducts().get(i).getTitle(), "验证sTitle");
				DataUtil.verify(orderSql.getProducts().get(i).getBondedArea(),
						orderMongo.getProducts().get(i).getBondedArea(),
						"验证iBondedArea");
				DataUtil.verify(orderSql.getProducts().get(i).getPriceType(),
						orderMongo.getProducts().get(i).getPriceType(),
						"验证iPriceType");
				DataUtil.verify(orderSql.getProducts().get(i)
						.getPrdRefundStatus(), orderMongo.getProducts().get(i)
						.getPrdRefundStatus(), "验证iProductRefundStatus");
				DataUtil.verify(orderSql.getProducts().get(i)
						.getRefundChannel(), orderMongo.getProducts().get(i)
						.getRefundChannel(), "验证iProductRefundChannel");
				DataUtil.verify(orderSql.getProducts().get(i).getPrdFreight(),
						orderMongo.getProducts().get(i).getPrdFreight(),
						"验证fFreight");
				DataUtil.verify(
						orderSql.getProducts().get(i).getPrdYmtCoupon(),
						orderMongo.getProducts().get(i).getPrdYmtCoupon(),
						"验证fYmtCouponAmount");
				DataUtil.verify(orderSql.getProducts().get(i)
						.getPrdSellerCoupon(), orderMongo.getProducts().get(i)
						.getPrdSellerCoupon(), "验证fSellerCouponAmount");
				DataUtil.verify(orderSql.getProducts().get(i).getTariffType(),
						orderMongo.getProducts().get(i).getTariffType(),
						"验证iTariffType");
				DataUtil.verify(orderSql.getProducts().get(i).getSalesType(),
						orderMongo.getProducts().get(i).getSalesType(),
						"验证iSalesType");
				DataUtil.verify(orderSql.getProducts().get(i).getPrdPreSale(),
						orderMongo.getProducts().get(i).getPrdPreSale(),
						"验证bPreSale");
				DataUtil.verify(orderSql.getProducts().get(i).getPspProduct(),
						orderMongo.getProducts().get(i).getPspProduct(),
						"验证bPspProduct");

				DataUtil.verify(orderSql.getProducts().get(i)
						.getPrdDiscount3P(), orderMongo.getProducts().get(i)
						.getPrdDiscount3P(), "验证fThirdPartyDiscount");
				DataUtil.verify(orderSql.getProducts().get(i).getReturn7d(),
						orderMongo.getProducts().get(i).getReturn7d(),
						"验证bSupportRtnWithoutReason");
				DataUtil.verify(
						orderSql.getProducts().get(i).getPrdPromotionAmount(),
						orderMongo.getProducts().get(i).getPrdPromotionAmount(),
						"验证fSellerPromotionAmount");
				DataUtil.verify(orderSql.getProducts().get(i).getPackageNo(),
						orderMongo.getProducts().get(i).getPackageNo(),
						"验证sPackageNo");
				DataUtil.verify(orderSql.getProducts().get(i).getFreightFree(),
						orderMongo.getProducts().get(i).getFreightFree(),
						"验证bFreightFree");
				DataUtil.verify(orderSql.getProducts().get(i)
						.getProductVersion(), orderMongo.getProducts().get(i)
						.getProductVersion(), "验证productVersion");
				DataUtil.verify(orderSql.getProducts().get(i).getProductCode(),
						orderMongo.getProducts().get(i).getProductCode(),
						"验证productCode");

				Logger.comment("比对sql数据库Ymt_OrderInfoExt表数据");
				DataUtil.verify(orderSql.getProducts().get(i).getActId(),
						orderMongo.getProducts().get(i).getActId(),
						"验证iActivityId");
				DataUtil.verify(orderSql.getProducts().get(i)
						.getActTemplateId(), orderMongo.getProducts().get(i)
						.getActTemplateId(), "验证iActivityTemplateId");
				DataUtil.verify(orderSql.getProducts().get(i).getPromotionId(),
						orderMongo.getProducts().get(i).getPromotionId(),
						"验证PromotionId");
				DataUtil.verify(orderSql.getProducts().get(i)
						.getPromotionType(), orderMongo.getProducts().get(i)
						.getPromotionType(), "验证promotionType");
				DataUtil.verify(orderSql.getProducts().get(i)
						.getPromotionName(), orderMongo.getProducts().get(i)
						.getPromotionName(), "验证PromotionName");
				DataUtil.verify(
						orderSql.getProducts().get(i).getPromotionCondition(),
						orderMongo.getProducts().get(i).getPromotionCondition(),
						"验证MatchCondition");
				DataUtil.verify(orderSql.getProducts().get(i)
						.getPromotionContent(), orderMongo.getProducts().get(i)
						.getPromotionContent(), "验证PromotionValue");
				DataUtil.verify(orderSql.getProducts().get(i)
						.getPromotionAmount(), orderMongo.getProducts().get(i)
						.getPromotionAmount(), "验证ReducedAmount");
				DataUtil.verify(orderSql.getProducts().get(i).getRefundCount(),
						orderMongo.getProducts().get(i).getRefundCount(),
						"验证RefundProductNum");
				DataUtil.verify(orderSql.getProducts().get(i).getPrdRefundNo(),
						orderMongo.getProducts().get(i).getPrdRefundNo(),
						"验证RefundBillNo");

			}

			Logger.comment("比对sql数据库Ymt_OrderInfoSub表数据");

			for (int i = 0; i < orderSql.getSubProducts().size(); i++) {

				Logger.comment("校验第" + (i + 1) + "个组合商品");

				SubProduct sqlSubProduct = orderSql.getSubProducts().get(i);
				SubProduct mongoSubProduct = orderMongo.getSubProducts().get(i);

				DataUtil.verify(sqlSubProduct.getCatalogId(),
						mongoSubProduct.getCatalogId(), "验证catalogId");

				DataUtil.verify(sqlSubProduct.getSubTitle(),
						mongoSubProduct.getSubTitle(), "验证subTitle");

				DataUtil.verify(sqlSubProduct.getSubCatalogId(),
						mongoSubProduct.getSubCatalogId(), "验证subCatalogId");

				DataUtil.verify(sqlSubProduct.getFirstCatId(),
						mongoSubProduct.getFirstCatId(), "验证firstCatId");

				DataUtil.verify(sqlSubProduct.getSecondCatId(),
						mongoSubProduct.getSecondCatId(), "验证secondCatId");

				DataUtil.verify(sqlSubProduct.getThirdCatId(),
						mongoSubProduct.getThirdCatId(), "验证thirdCatId");

				DataUtil.verify(sqlSubProduct.getSku(),
						mongoSubProduct.getSku(), "验证sku");

				DataUtil.verify(sqlSubProduct.getNum(),
						mongoSubProduct.getNum(), "验证num");

				DataUtil.verifyDecimalEquals(sqlSubProduct.getOriginalPrice(),
						mongoSubProduct.getOriginalPrice(), "验证originalPrice");

				DataUtil.verifyDecimalEquals(sqlSubProduct.getPrice(),
						mongoSubProduct.getPrice(), "验证price");

				DataUtil.verifyDecimalEquals(sqlSubProduct.getFreight(),
						mongoSubProduct.getFreight(), "验证freight");

				DataUtil.verifyDecimalEquals(sqlSubProduct.getDiscount(),
						mongoSubProduct.getDiscount(), "验证discount");

				DataUtil.verifyDecimalEquals(sqlSubProduct.getYmtCoupon(),
						mongoSubProduct.getYmtCoupon(), "验证ymtCoupon");

				DataUtil.verifyDecimalEquals(sqlSubProduct.getSellerCoupon(),
						mongoSubProduct.getSellerCoupon(), "验证sellerCoupon");

				DataUtil.verifyDecimalEquals(
						sqlSubProduct.getThirdPartyDiscount(),
						mongoSubProduct.getThirdPartyDiscount(),
						"验证thirdPartyDiscount");

				DataUtil.verifyDecimalEquals(sqlSubProduct.getPromotion(),
						mongoSubProduct.getPromotion(), "验证promotion");

			}

			if (orderSql.getRefunds().size() > 0)
				Logger.comment("比对sql数据库Ymt_RefundBill表数据");

			for (int i = 0; i < orderSql.getRefunds().size(); i++) {

				Logger.comment("校验第" + (i + 1) + "个退款单");

				DataUtil.verify(orderSql.getRefunds().get(i).getRefundNo(),
						orderMongo.getRefunds().get(i).getRefundNo(),
						"验证RefundBillNo");
				DataUtil.verify(orderSql.getRefunds().get(i).getRefundAmount(),
						orderMongo.getRefunds().get(i).getRefundAmount(),
						"验证RefundAmount");
				DataUtil.verify(orderSql.getRefunds().get(i)
						.getRefundAmountCash(), orderMongo.getRefunds().get(i)
						.getRefundAmountCash(), "验证RefundedAmountOfCash");
				DataUtil.verify(orderSql.getRefunds().get(i).getRefund3P(),
						orderMongo.getRefunds().get(i).getRefund3P(),
						"验证RefundedDiscountOfThirdParty");
				DataUtil.verifyDateEquals(orderSql.getRefunds().get(i)
						.getRefundTime(), orderMongo.getRefunds().get(i)
						.getRefundTime(), "验证AddTime");
				DataUtil.verify(orderSql.getRefunds().get(i).getRefundStatus(),
						orderMongo.getRefunds().get(i).getRefundStatus(),
						"验证SalesRefundStatus");

				DataUtil.verifyDecimalEquals(orderSql.getRefunds().get(i)
						.getRefundAmountCop(), orderMongo.getRefunds().get(i)
						.getRefundAmountCop(), "验证 退款优惠券refundAmountCop");

				DataUtil.verifyDecimalEquals(orderSql.getRefunds().get(i)
						.getRefundAmountGift(), orderMongo.getRefunds().get(i)
						.getRefundAmountGift(), "验证 退款红包refundAmountGift");

				DataUtil.verifyDecimalEquals(
						orderSql.getRefunds().get(i).getRefundAmountFreight(),
						orderMongo.getRefunds().get(i).getRefundAmountFreight(),
						"验证 退款运费refundAmountFreight");

			}

			Logger.comment("校验Ymt_OrderBiz表");

			DataUtil.verify(orderSql.getBizId(), orderMongo.getBizId(),
					"验证bizId");
			DataUtil.verify(orderSql.getBizStatus(), orderMongo.getBizStatus(),
					"验证bizStatus");
			DataUtil.verify(orderSql.getBizSubType(),
					orderMongo.getBizSubType(), "验证bizSubType");
			DataUtil.verify(orderSql.getBizType(), orderMongo.getBizType(),
					"验证bizType");

			if (orderSql.getStatusLog().size() > 0)
				Logger.comment("校验Ymt_TradingStatus表数据");

			for (int i = 0; i < orderSql.getStatusLog().size(); i++) {

				DataUtil.verify(orderSql.getStatusLog().size(), orderMongo
						.getStatusLog().size(),
						"验证orderMongo.getStatusLog() 结果记录");
				Logger.comment("校验第" + (i + 1) + "个交易日志");
				DataUtil.verify(orderSql.getStatusLog().get(i).getLogStatus(),
						orderMongo.getStatusLog().get(i).getLogStatus(),
						"验证iTradingStatus");
				DataUtil.verify(orderSql.getStatusLog().get(i).getMemo(),
						orderMongo.getStatusLog().get(i).getMemo(), "验证mMemo");
				DataUtil.verifyDateEquals(orderSql.getStatusLog().get(i)
						.getLogTime(), orderMongo.getStatusLog().get(i)
						.getLogTime(), "验证dUpdateTime");
			}

			if (orderSql.getDelivery() != null) {

				Logger.comment("比对sql数据库Ymt_Order_Frozen表数据");

				Logger.verifyNotNull(orderMongo.getDelivery(),
						"验证orderMongo Delivery 不为null");

				DataUtil.verifyDateEquals(orderSql.getDelivery()
						.getUpdateTime(), orderMongo.getDelivery()
						.getUpdateTime(), "验证dUpdateTime");
				DataUtil.verifyDateEquals(orderSql.getDelivery()
						.getFrozenTime(), orderMongo.getDelivery()
						.getFrozenTime(), "验证dFrozenTime");
				DataUtil.verify(orderSql.getDelivery().getPause(), orderMongo
						.getDelivery().getPause(), "验证bPause");
				DataUtil.verify(orderSql.getDelivery().getBizType(), orderMongo
						.getDelivery().getBizType(), "验证BusynessTypes");
				DataUtil.verify(orderSql.getDelivery().getDelayUserId(),
						orderMongo.getDelivery().getDelayUserId(), "验证iUserId");

				DataUtil.verify(orderSql.getDelivery().getBillCode() == null
						? null
						: orderSql.getDelivery().getBillCode(), sellerIndexBean
						.getBillCode(), "验证BillCode");

			} else {

				if (orderMongo.getDelivery() != null) {
					DataUtil.verify(null, orderMongo.getDelivery()
							.getBillCode().size() < 1 ? null : orderMongo
							.getDelivery().getBillCode(),
							"验证mongo 数据库BillCode为null");
				}
			}

			verifyMongoIndex(orderSql, sellerIndexBean, userIndexBean);

			verifyES(orderSql, sellerIndexBean, orderEsBean);

		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			Logger.debug(e.getMessage());
		}

	}
	/**
	 * 校验Mongo Index索引数据
	 * 
	*/
	private static void verifyMongoIndex(OrderBean orderSql,
			SellerIndexBean sellerIndexBean, UserIndexBean userIndexBean) {

		Logger.comment("校验Mongo库UserIndex表数据");

		DataUtil.verify(orderSql.getId(), userIndexBean.getId(), "验证iOrderId");
		DataUtil.verify(orderSql.getUserId(), userIndexBean.getUserId(),
				"验证iUserId");
		DataUtil.verify(orderSql.getMainOrderId(),
				userIndexBean.getMainOrderId(), "验证iMainOrderId");
		DataUtil.verify(orderSql.getTradingStatus(),
				userIndexBean.getTradingStatus(), "验证iTradingStatus");
		DataUtil.verifyDateEquals(orderSql.getAddTime(),
				userIndexBean.getAddTime(), "验证dAddTime");
		DataUtil.verifyDateEquals(orderSql.getReceiveTime(),
				userIndexBean.getReceiveTime(), "验证dreceiveTime");
		DataUtil.verify(orderSql.getDeleted(), userIndexBean.getDeleted(),
				"验证bDeleted");
		DataUtil.verify(!orderSql.getEvaluated() && orderSql.getCanEvaluate(),
				userIndexBean.getNeedsEvaluate(), "验证bEvaluated");

		Logger.comment("校验Mongo库SellerIndex表数据");

		DataUtil.verify(orderSql.getId(), sellerIndexBean.getId(), "验证iOrderId");
		DataUtil.verify(orderSql.getUserId(), sellerIndexBean.getUserId(),
				"验证iUserId");
		DataUtil.verify(orderSql.getMainOrderId(),
				sellerIndexBean.getMainOrderId(), "验证iMainOrderId");
		DataUtil.verify(orderSql.getSellerId(), sellerIndexBean.getSellerId(),
				"验证iBuyerid");
		DataUtil.verify(orderSql.getTradingStatus(),
				sellerIndexBean.getTradingStatus(), "验证iTradingStatus");
		DataUtil.verifyDateEquals(orderSql.getAddTime(),
				sellerIndexBean.getAddTime(), "验证dAddTime");
		DataUtil.verifyDateEquals(orderSql.getPaidTime(),
				sellerIndexBean.getPaidTime(), "验证dPaidTime");
		DataUtil.verifyDateEquals(orderSql.getAcceptTime(),
				sellerIndexBean.getAcceptTime(), "验证dAcceptTime");
		DataUtil.verifyDateEquals(orderSql.getDeliveryTime(),
				sellerIndexBean.getDeliveryTime(), "验证dDispathTime");
		DataUtil.verify(orderSql.getLocalDelivery(),
				sellerIndexBean.getLocalDelivery(), "验证bDomesticDelivered");
		DataUtil.verify(orderSql.getPreSale(), sellerIndexBean.getPreSale(),
				"验证bPreSale");
		DataUtil.verify(
				orderSql.getRemarkLevel() == null ? 0 : orderSql
						.getRemarkLevel(), sellerIndexBean.getRemarkLevel(),
				"验证iRemarkLevel");

		//用户应付
		DataUtil.verify(orderSql.getPayableAmount(),
				sellerIndexBean.getUserPay(), "验证userPay");
		// 成交额(TotalPrice + Freight)
		DataUtil.verify(orderSql.getFreight().add(orderSql.getTotalPrice()),
				sellerIndexBean.getSales(), "验证sales");
		// 平台优惠券
		DataUtil.verify(orderSql.getYmtCouponAmount(),
				sellerIndexBean.getYmtCouponAmount(), "验证ymtCop");

		BigDecimal usePay = BigDecimal.ZERO;
		// 直播成交额
		BigDecimal sales = BigDecimal.ZERO;
		BigDecimal ymtCoupon = BigDecimal.ZERO;
		Integer dlvType = null;

		for (Product prd : orderSql.getProducts()) {

			if (prd.getSalesType() == null || prd.getSalesType() == 2) {

				sales = sales.add(
						zeroIfNull(prd.getPrdPrice()).multiply(
								new BigDecimal(prd.getPrdCount()))).add(
						zeroIfNull(prd.getPrdFreight()));
				ymtCoupon = ymtCoupon.add(zeroIfNull(prd.getPrdYmtCoupon()));
				usePay = usePay.add(zeroIfNull(prd.getPrdPrice())
						.multiply(new BigDecimal(prd.getPrdCount()))
						.add(zeroIfNull(prd.getPrdFreight()))
						.add(zeroIfNull(prd.getPrdDiscount()))
						.subtract(zeroIfNull(prd.getPrdPromotionAmount()))
						.subtract(zeroIfNull(prd.getPrdSellerCoupon()))
						.subtract(zeroIfNull(prd.getPrdYmtCoupon())));

			}
			if (dlvType == null) {
				dlvType = prd.getDeliveryType();
			}

		}

		// 直播成交额
		DataUtil.verifyDecimalEquals(sales, sellerIndexBean.getSalesLive(),
				"验证salesLive");
		// 直播用户应付
		DataUtil.verifyDecimalEquals(usePay, sellerIndexBean.getUserPayLive(),
				"验证userPayLive");
		//直播平台优惠券
		DataUtil.verifyDecimalEquals(ymtCoupon,
				sellerIndexBean.getYmtCouponAmountLive(),
				"验证ymtCouponAmountLive");

		DataUtil.verifyDecimalEquals(orderSql.getFund().getRefundCash(),
				sellerIndexBean.getRefundCash(), "验证refundCash");

		DataUtil.verifyDecimalEquals(orderSql.getFund().getRefundCoupon(),
				sellerIndexBean.getRefundCoupon(), "验证refundCoupon");

		// 物流类型
		DataUtil.verify(dlvType, sellerIndexBean.getDeliveryType(), "验证dlvTp");

		// 买家登录Id
		DataUtil.verify(orderSql.getUserLogin(),
				sellerIndexBean.getUserLogin(), "验证sBuyerLoginId");

		DataUtil.verify(orderSql.getReceiver(), sellerIndexBean.getReceiver(),
				"验证recv");

		DataUtil.verify(orderSql.getRefunds().size() > 0 ? true : false,
				sellerIndexBean.getRefunded(), "验证refunded");

		/*		DataUtil.verify(orderSql.getBizId(), sellerIndexBean.getBizId(),
						"验证bizId");
				DataUtil.verify(orderSql.getBizStatus(),
						sellerIndexBean.getBizStatus(), "验证bizStatus");

				DataUtil.verify(orderSql.getBizType(), sellerIndexBean.getBizType(),
						"验证bizTp");
		*/
		DataUtil.verify(
				getHidden(orderSql.getBizType(), orderSql.getBizStatus()),
				sellerIndexBean.getHidden(), "验证hidden");

	}
	/**
	 * 校验ES索引数据
	 * 
	*/
	private static void verifyES(OrderBean orderSql,
			SellerIndexBean sellerIndexBean, OrderEsBean orderEsBean) {
		Logger.comment("校验ES索引数据");

		try {
			Thread.sleep(3000);
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		DataUtil.verify(orderSql.getId(), orderEsBean.getId(), "验证id");
		DataUtil.verify(orderSql.getMainOrderId(), orderEsBean.getMain(),
				"验证main");

		// 商品名称集合
		List<String> titles = new ArrayList<String>();

		for (Product pro : orderSql.getProducts()) {
			titles.add(pro.getTitle());
		}

		DataUtil.verify(titles, Arrays.asList(orderEsBean.getTitle()),
				"验证title");

		for (int i = 0; i < orderSql.getProducts().size(); i++) {
			Logger.comment("校验ES索引第" + (i + 1) + "商品数据");
			DataUtil.verify(orderSql.getProducts().get(i).getProductId(),
					orderEsBean.getPrd().get(i).getPrdId(), "验证prdId");
			DataUtil.verify(orderSql.getProducts().get(i).getTitle(),
					orderEsBean.getPrd().get(i).getTitle(), "验证title");
			DataUtil.verify(orderSql.getProducts().get(i).getPrdCount(),
					orderEsBean.getPrd().get(i).getCount(), "验证count");
		}
		Logger.comment("校验ES索引商品数据结束");

		DataUtil.verify(orderSql.getUserId(), orderEsBean.getUser(), "验证user");

		DataUtil.verify(orderSql.getUserLogin(), orderEsBean.getUserLgi(),
				"验证userLgi");
		DataUtil.verify(orderSql.getReceiver(), orderEsBean.getRecv(), "验证recv");

		DataUtil.verify(orderSql.getPhone(), orderEsBean.getPhone(), "验证phone");
		DataUtil.verify(orderSql.getSellerId(), orderEsBean.getSeller(),
				"验证seller");
		DataUtil.verify(orderSql.getTradingStatus(), orderEsBean.getSt(),
				"验证st");

		// DataUtil.verifyDateEquals(expected, actual, desc);
		DataUtil.verifyDateEquals(orderSql.getAddTime(),
				orderEsBean.getAddTm(), "验证addTm");
		DataUtil.verifyDateEquals(orderSql.getAcceptTime(),
				orderEsBean.getAcpTm(), "验证acpTm");
		DataUtil.verifyDateEquals(orderSql.getPaidTime(),
				orderEsBean.getPaidTm(), "验证paidTm");
		DataUtil.verify(orderSql.getSellerCouponCode(),
				orderEsBean.getSellerCopCod(), "验证sellerCopCod");

		DataUtil.verify(orderSql.getPayableAmount(), orderEsBean.getUserPay(),
				"验证userPay");

		DataUtil.verify(sellerIndexBean.getSales(), orderEsBean.getSales(),
				"验证sales");
		DataUtil.verify(orderSql.getYmtCouponCode(),
				orderEsBean.getYmtCopCod(), "验证ymtCopCod");

		DataUtil.verify(orderSql.getYmtCouponAmount(), orderEsBean.getYmtCop(),
				"验证ymtCop");

		DataUtil.verify(
				sellerIndexBean.getBillCode(),
				orderEsBean.getDlvCode() == null ? null : Arrays
						.asList(orderEsBean.getDlvCode()), "验证dlvCode");

		DataUtil.verify(sellerIndexBean.getDeliveryType(),
				orderEsBean.getDlvTp(), "验证dlvTp");
		DataUtil.verifyDateEquals(sellerIndexBean.getDeliveryTime(),
				orderEsBean.getDlvTm(), "验证dlvTm");

		DataUtil.verifyDateEquals(sellerIndexBean.getLocalDelivery(),
				orderEsBean.getLocDlv(), "验证locDlv");
		DataUtil.verifyDateEquals(orderSql.getReceiveTime(),
				orderEsBean.getRecvTm(), "验证recvTm");
		DataUtil.verifyDateEquals(orderSql.getPreSale(),
				orderEsBean.getPreSale(), "验证preSale");
		DataUtil.verifyDateEquals(orderSql.getRefunds().size() < 1
				? false
				: true, orderEsBean.getRfded(), "验证rfded");
		DataUtil.verifyDateEquals(orderSql.getRemarkLevel(),
				orderEsBean.getRmklvl(), "验证rmklvl");

		DataUtil.verifyDateEquals(
				!orderSql.getEvaluated() && orderSql.getCanEvaluate(),
				orderEsBean.getEva(), "验证eva");
		DataUtil.verifyDateEquals(orderSql.getDeleted(), orderEsBean.getDel(),
				"验证del");

		DataUtil.verify(orderSql.getFund().getRefundCash(),
				orderEsBean.getRfdCsh(), "验证rfdCsh");

		DataUtil.verify(orderSql.getFund().getRefundCoupon(),
				orderEsBean.getRfdCop(), "验证rfdCop");

		DataUtil.verifyDateEquals(orderSql.getBizId(), orderEsBean.getBizId(),
				"验证bizId");
		DataUtil.verifyDateEquals(orderSql.getBizType(),
				orderEsBean.getBizTp(), "验证bizType");
		DataUtil.verifyDateEquals(orderSql.getBizStatus(),
				orderEsBean.getBizSt(), "验证bizStatus");

		DataUtil.verifyDateEquals(sellerIndexBean.getUserPayLive(),
				orderEsBean.getLvPay(), "验证lvPay");
	}

	public static BigDecimal zeroIfNull(BigDecimal number) {
		if (null == number) {
			return BigDecimal.ZERO;
		} else {
			return number;
		}

	}
	/**
	 * 
	 * syncOrderCmd 指令同步
	 * 
	 * @param orderId
	 * @param orderSyncCmdEnum
	 *            指令枚举
	 *
	 */
	public static void syncOrderCmd(Integer orderId,
			OrderSyncCmdEnum orderSyncCmdEnum) {

		SyncOrderCmdBean syncOrderCmdBean = new SyncOrderCmdBean();
		SyncOrderCmdCall syncOrderCmdCall = new SyncOrderCmdCall();

		syncOrderCmdBean
				.setCmdReqId(TestDataManager.getRandomUUID().toString());
		syncOrderCmdBean.setOrderId(orderId);
		syncOrderCmdBean.setCommand(orderSyncCmdEnum.toString());

		syncOrderCmdCall.setData(false, syncOrderCmdBean);
		try {
			syncOrderCmdCall.callService();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}
	/**
	 * 修改订单折扣和运费
	 * @param orderId 
	 * @param sellerId
	 * */
	public static void changeOrderDiscount(int orderId, int sellerId) {

		ChangeOrderDiscountBean changeorderdiscountbean = new ChangeOrderDiscountBean();
		ChangeOrderDiscountCall changeorderdiscountcall = new ChangeOrderDiscountCall();

		try {

			// 参数
			BigDecimal discount = new BigDecimal(1 + new Random().nextInt(50));

			changeorderdiscountbean.setDiscount(discount);
			String discountTime = YMTDateUtil.getSysTime();
			changeorderdiscountbean.setDiscountTime(discountTime);

			BigDecimal freight = new BigDecimal(new Random().nextInt(150));

			changeorderdiscountbean.setFreight(freight);
			changeorderdiscountbean.setOrderId(orderId);
			changeorderdiscountbean.setSellerId(sellerId);
			// 发送请求
			changeorderdiscountcall.setData(false, changeorderdiscountbean);
			changeorderdiscountcall.callService();

		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * 判断砍价团订单是否需要隐藏
	 * @param bizType  业务类型
	 * @param bizStatus  业务状态
	 * */
	private static Boolean getHidden(Integer bizType, Integer bizStatus) {
		if (bizType == null || bizType != 1 || bizStatus == null) {
			return null;
		}
		return bizStatus != 3;
	}

	/**
	 * 修改订单物流类型
	 * @param orderId  
	 * @param sellerId
	 * @param logisticsTypeEnum
	 * */
	public static void changeLogisticsType(int orderId, int sellerId,
			LogisticsTypeEnum logisticsTypeEnum) {
		try {

			ChangeLogisticsTypeReq codnbean = new ChangeLogisticsTypeReq();
			ChangeLogisticsTypeCall codncall = new ChangeLogisticsTypeCall();

			codnbean.setLogisticsType(logisticsTypeEnum.getCode());

			codnbean.setOrderId(orderId);
			codnbean.setSellerId(sellerId);

			// 发送请求
			codncall.setData(false, codnbean);
			codncall.callService();

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	public static void main(String args[]) {
		//syncOrderCmd(112522659, OrderSyncCmdEnum.UPDATE_USER);

		//modifyDeliverBillCode(112523215, 3383, "p6XrHZQu3F", "DB683214922US");

		syncOrderCmd(2138527851, OrderSyncCmdEnum.PLACE);
		//syncOrderCmd(112523215, OrderSyncCmdEnum.CHANGE_BILLCODE);
	}

}
